<?php

namespace app\admin\model;

use think\Model;


class SendgoodsService extends Model
{

    

    

    // 表名
    protected $name = 'sendgoods_service';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'usetimestart_text',
        'usetimeend_text',
        'reservetime_text',
        'usetime_text',
        'state_text'
    ];
    

    
    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1'), '2' => __('State 2')];
    }


    public function getUsetimestartTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['usetimestart']) ? $data['usetimestart'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUsetimeendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['usetimeend']) ? $data['usetimeend'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReservetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reservetime']) ? $data['reservetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUsetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['usetime']) ? $data['usetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setUsetimestartAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUsetimeendAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReservetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUsetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function shoprogoods()
    {
        return $this->belongsTo('ShoproGoods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shoprostore()
    {
        return $this->belongsTo('ShoproStore', 'shopro_store_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shoprostoreproject()
    {
        return $this->belongsTo('ShoproStoreProject', 'shopro_store_project_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shoprostorewaiter()
    {
        return $this->belongsTo('ShoproStoreWaiter', 'shopro_store_waiter_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
